package com.lishe.lishe.lishe.bean;

import com.google.gson.annotations.SerializedName;

import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by shino on 2017/8/11.
 */

public class OrderObject implements Serializable {
    /**
     * 订单状态：0、全部订单；1、待付款；2、代发货；3、待收货；4、已完成；5、退款/退货
     */
    private int orderType = 0;

    // 	福利订单号
    @SerializedName("orderNo")
    private String orderNo;
    // 	福利订单状态Id
    @SerializedName("id")
    private String orderId;
    // 	福利订单状态
    @SerializedName("orderStatus")
    private String orderStatus;//订单状态：0:支付成功 1:员工领取中 2:订单准备中 3:已发货 4:已完成’


    /**
     * 订单中商品总金额
     */
    private double orderMoney = 0;

    /**
     * 订单支付id
     */
    private String orderPaymentId;

    /**
     * 订单生成时间
     */
    @SerializedName("createTime")
    private String orderCreateTime;
    /**
     * 订单名称
     */
    private String orderName;

    /**
     * 订单下的店铺
     */
    private LinkedList<BusinessObject> lisBusinessObjects = new LinkedList();
    /**
     * 订单备注
     */
    private String orderNote;

    /**
     * 生成订单及确认订单所需参数
     */
    private ArrayList<String> carIds = new ArrayList<>();//create的所有carid
    private List<String> shopIds = new ArrayList<>();//createfinnish的所有商店shopIds
    private List<String> itemIds = new ArrayList<>();//createfinnish的所有itemIds
    private List<String> dlytmplIds = new ArrayList<>();//createfinnish的所有dlytmplIds
    private List<String> postFees = new ArrayList<>();//createfinnish的所有postFees
    private List<String> skuIds = new ArrayList<>();//createfinnish的所有skuIds
    private List<String> remarks = new ArrayList<>();//createfinnish的所有remarks


    public int getOrderType() {
        return orderType;
    }

    public void setOrderType(int orderType) {
        this.orderType = orderType;
    }

    public double getOrderMoney() {
        if (orderMoney == 0) {
            return getBusinessTotalMoney();
        } else {
            return orderMoney;
        }
    }

    public void setOrderMoney(double orderMoney) {
        this.orderMoney = orderMoney;
    }

    public String getOrderCreateTime() {
        return orderCreateTime;
    }

    public void setOrderCreateTime(String orderCreateTime) {
        this.orderCreateTime = orderCreateTime;
    }

    public String getOrderNote() {
        return orderNote;
    }

    public void setOrderNote(String orderNote) {
        this.orderNote = orderNote;
    }

    public LinkedList<BusinessObject> getLisBusinessObjects() {
        return lisBusinessObjects;
    }

    public void setLisBusinessObjects(LinkedList<BusinessObject> lisBusinessObjects) {
        this.lisBusinessObjects = lisBusinessObjects;
    }

    public String getOrderName() {
        return orderName;
    }

    public String getOrderPaymentId() {
        return orderPaymentId;
    }

    public void setOrderPaymentId(String orderPaymentId) {
        this.orderPaymentId = orderPaymentId;
    }

    public List<String> getShopIds() {
        return shopIds;
    }

    public void setShopIds(List<String> shopIds) {
        this.shopIds = shopIds;
    }

    public List<String> getItemIds() {
        return itemIds;
    }

    public void setItemIds(List<String> itemIds) {
        this.itemIds = itemIds;
    }

    public List<String> getDlytmplIds() {
        return dlytmplIds;
    }

    public void setDlytmplIds(List<String> dlytmplIds) {
        this.dlytmplIds = dlytmplIds;
    }

    public List<String> getPostFees() {
        return postFees;
    }

    public void setPostFees(List<String> postFees) {
        this.postFees = postFees;
    }

    public List<String> getSkuIds() {
        return skuIds;
    }

    public void setSkuIds(List<String> skuIds) {
        this.skuIds = skuIds;
    }

    public List<String> getRemarks() {
        return remarks;
    }

    public void setRemarks(List<String> remarks) {
        this.remarks = remarks;
    }

    public ArrayList<String> getCarIds() {
        return carIds;
    }

    public void setCarIds(ArrayList<String> carIds) {
        this.carIds = carIds;
    }

    public String getOrderNo() {
        return orderNo;
    }

    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public String getOrderStatus() {
        return orderStatus;
    }

    public void setOrderStatus(String orderStatus) {
        this.orderStatus = orderStatus;
    }

    /**
     * 订单消费金额
     *
     * @return
     */
    public double getBusinessTotalMoney() {
        double money = 0;
        for (int i = 0; i < lisBusinessObjects.size(); i++) {
            BusinessObject business = lisBusinessObjects.get(i);
            money = money + business.getBusinessTotalMoney();
        }
        return money;
    }

    public void setOrderName(String orderName) {
        this.orderName = orderName;
    }

    public void optJson(OrderObject orderObject, JSONObject jsonObject) {
        orderObject.setOrderMoney(jsonObject.optInt("money"));
        orderObject.setOrderPaymentId(jsonObject.optString("payment_id"));
        orderObject.setOrderCreateTime(jsonObject.optString("created_time"));
    }

    //订单状态：0:支付成功 1:员工领取中 2:订单准备中 3:已发货 4:已完成’
    public String getorderStatusToString() {
        String msg = null;
        if (orderStatus == null) {
            return msg;
        }
        switch (orderStatus) {
            case "0":
                msg = "支付成功";
                break;
            case "1":
                msg = "员工领取中";
                break;
            case "2":
                msg = "订单准备中";
                break;
            case "3":
                msg = "已发货";
                break;
            case "4":
                msg = "已完成";
                break;
        }
        return msg;
    }
}
